Yacon.widget.TRadio = function(element){
	this.element = element;
};

Yacon.widget.TRadio.prototype = {
		
	/* 获取HTML信息 */
	getHtml: function(){
		
		var html = "";
		
		//标题拼接

		if(!Yacon.isTrue(this.element.lableVisible) 
		&& !Yacon.isTrue(this.element.hintVisible)){
			html += "<div>";
		}else{
			html += "<div class='input-group'>";
		}
		
		var lableClass = "";
		
		if(this.isEnable() || this.parent.view.isStatic){
			lableClass += "bk-bg-primary";
		}else{
			lableClass += "bk-bg-brown";
		}
		
		if(this.element.btnState){
			lableClass = "bk-bg-"+this.element.btnState;
		}
		
		if(Yacon.isTrue(this.element.lableVisible)){
		
			html += "<span class='input-group-btn "+lableClass+"' "+this.getColorStyle()+" >";
			
			html += new Yacon.widget.TButton(this.element.labelMenu).getFormHtml();
			
/*			html += "<button class='btn "+lableClass+"' "+this.getColorStyle()+" type='button'>"+this.getLableHtml()+"</button>";
*/				
			html += "</span>";
			
		}
		
		html += this.getDataHtml();
		
		html += "</div>";
		
		return html;
		
	},
	
	getDataHtml: function(){
		
		var html = "";
		
		html += "<div style='padding-left:20px;line-height:21px;' field-name='"+this.element.name+"' "
		
		html += " class='lily-field' ";
		
		html += " field-type='radio' ";
		
		html += ">";
		
		if(!Yacon.isEmpty(this.element.data)){
			
			for(var i=0;i<this.element.data.length;i++){
				
				html += "<label class='radio-inline'>";
				
				var active = this.element.data[i];
				
				html += "<input value='"+active.key+"' type='radio' style='vertical-align:middle;' ";
				
				html += " field-key='"+active.key+"' field-value='"+active.value+"' ";
				
				html += " name='"+this.element.name+"' ";
				
				if(!this.isEnable()){
					html += " disabled ";
				}
				
				html += this.getDefaultValue(active.key);
				
				html += " >";
				
				html += "<span style='vertical-align:middle;'>";
				
				html += active.value;
				
				html += "</span>";
				
				html += "</label>";
				
			}
			
		}
		
		html += "</div>"
		
		return html;
		
	},
	
	getDefaultValue: function(value){
		
		this.page = this.parent.page;
		var state = this.page.element.parameter.state;
		
		if(Yacon.isEmpty(state)){
			state = "active";
		}
		
		if(!Yacon.isEmpty(this.element.commonVal)){	
					
			if(this.element.commonVal == value){
				return "checked";
			}else{
				return "";
			}
		}
		
		else{
			
			if(state == "insert"){
				if(!Yacon.isEmpty(this.element.insertVal)){	
					
					if(this.element.insertVal == value){
						return "checked";
					}else{
						return "";
					}	
				}else{
					return "";
				}
			}
			
			else if(state == "edit"){
				if(!Yacon.isEmpty(this.element.editVal)){
					
					if(this.element.editVal == value){
						return "checked";
					}else{
						return "";
					}
					
				}else{
					return "";
				}
			}
			
			else {
				return "";
			}
			
		}
	},
	
	isEnable: function(){
		
		this.page = this.parent.page;
		var state = this.page.element.parameter.state;
		
		if(Yacon.isEmpty(state)){
			state = "active";
		}
		
		if(!this.element.isEnable){
			return false;
		}
		
		if(state == "insert"){
			return this.element.isInsert;
		}else if(state == "edit"){
			return this.element.isEdit;
		}else if(state == "past"){
			return false;
		}
		else{
			return true;
		}
		
	},
	
	getColorStyle: function(){
		
		var html = "";
		
		var btnColor = "";
		
		if(!Yacon.isEmpty(this.element.fontColor)){
			btnColor += "color:"+this.element.fontColor+" !important;";
		}
		
		if(!Yacon.isEmpty(this.element.backColor)){
			btnColor += " background-color:"+this.element.backColor+" !important;";
			btnColor += " border-color:"+this.element.backColor+" !important;";
		}
		
		if(!Yacon.isEmpty(btnColor)){
			html += " style='"+btnColor+"' ";
		}
		
		return html;
		
	},
	
	getLableHtml: function(){
		
		var html = "";
		var lable = this.element.text;
		var lableIco = this.element.ico;
		var lableType = this.element.viewType;
		
		if(Yacon.isEmpty(lableIco)){
			lableIco = "glyphicon glyphicon-tag";
		}
		
		if(lableType == "all"){
			html += "<span class='"+lableIco+"'></span>&nbsp;&nbsp;"+lable;
		}
		else if(lableType == "ico"){
			html += "<span class='"+lableIco+"'></span>";
		}
		else if(lableType == "label"){
			html += lable;
		}
		
		return html;
	},
	
	addEvent: function(){
		
	}	
};